package subject_set.top101;

/**
 * @author haomin
 * @date 2022/11/02 21:50
 **/
public class BM37 {
    public class Solution {
        public int lowestCommonAncestor (TreeNode root, int p, int q) {
            if(root.val == p || root.val == q) return root.val;
            if(root.val < p && root.val < q)
                return lowestCommonAncestor(root.right, p, q);
            if(root.val > p && root.val > q)
                return lowestCommonAncestor(root.left, p, q);
            return root.val;
        }
    }
}